package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.pojo.TbSellerExample;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description
 * @ClassName SellerServiceImpl
 * @Author RC
 * @date 2020.12.12 16:23
 */
@Component
@Service
public class SellerServiceImpl implements SellerService {
    @Autowired
    private TbSellerMapper tbSellerMapper;
    @Override
    public void saveSeller(TbSeller tbSeller) {

        int i = tbSellerMapper.insertSelective(tbSeller);
    }

    @Override

    public PageBean<TbSeller> getSellerList(Integer pageNumber, Integer pageSize, TbSeller tbSeller) {
        PageBean<TbSeller> page = new PageBean<>();
        page.setPageNumber(pageNumber);
        page.setPageSize(pageSize);
//分页查询
        List<TbSeller> list= tbSellerMapper.selectByPage(page.getStartIndex(),pageSize,tbSeller);
//查询总条数
        int i = tbSellerMapper.selectCounts();
        page.setTotalCount(i);
        page.setResult(list);
        return page;
    }

    @Override
    public TbSeller getInfoById(String sellerId) {

        return tbSellerMapper.selectByPrimaryKey(sellerId);
    }

    @Override
    public void getBunisee(TbSeller tbSeller) {
        TbSeller t = new TbSeller();
        t.setStatus(tbSeller.getStatus());
        t.setSellerId(tbSeller.getSellerId());
        int i = tbSellerMapper.updateByPrimaryKeySelective(t);

    }
    //认证
    @Override
    public TbSeller findUserByUserName(String username) {

        TbSellerExample example = new TbSellerExample();
        TbSellerExample.Criteria criteria = example.createCriteria();
        criteria.andSellerIdEqualTo(username);
        List<TbSeller> list = tbSellerMapper.selectByExample(example);
        return list == null || list.size() == 0 ? null : list.get(0);
    }
}
